package cn.edu.scau.cmi.liujiaming.chapter07;

interface ComputerAverage{
	public abstract double average(double a,double b);
}

class A implements ComputerAverage {
	public double average(double a,double b) {
		double average=(a+b)/2;
		return average;
	}
}

class B implements ComputerAverage {
	public double average(double a,double b) {
		double average=Math.sqrt(a*b);
		return average;
	}
}

public class Example7_3 {

	public static void main(String[] args) {
		double a=11.23,b=22.78;
		ComputerAverage computer=new A();
		System.out.printf("%5.2f和%5.2f的算术平均值为%5.2f\n",a,b,computer.average(a, b));
		computer=new B();
		System.out.printf("%5.2f和%5.2f的几何平均值为%5.2f\n",a,b,computer.average(a, b));
	}

}
